home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / REWIND.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  616 b   |  22 lines

  1. /*  rewind.c, from p. 458 of Turbo C Bible  */
  2. #include <stdio.h>
  3. main()
  4. {
  5.     FILE *infile;
  6.     char filename[80], buffer[81];
  7.     printf("Enter name of a test file: ");
  8.     gets(filename);
  9.                 /*  Open the file for reading  */
  10.     if ((infile = fopen(filename, "r")) == NULL)
  11.     {
  12.     printf("fopen failed.\n");
  13.     exit(0);
  14.     }
  15.                 /*  Read and display a line  */
  16.     fgets(buffer, 80, infile);
  17.     printf("Line read (before rewind): %s", buffer);
  18.                 /*  Rewind and read a line again  */
  19.     rewind(infile);
  20.     fgets(buffer, 80, infile);
  21.     printf("Line read (after rewind) : %s", buffer);
  22. }